<?php

/**
 * This is the model class for table "cotenant".
 *
 * The followings are the available columns in table 'cotenant':
 * @property integer $id
 * @property integer $idTenant
 * @property string $LastName
 * @property string $FirstName
 * @property string $MiddleInitial
 * @property string $DateOfBirth
 * @property string $OnLease
 * @property string $LastFreeAcess
 *
 * The followings are the available model relations:
 * @property Tenant $idTenant0
 */
class Cotenant extends CActiveRecord
{
	public $Name;
	/**
	 * Returns the static model of the specified AR class.
	 * @return Cotenant the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cotenant';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idTenant', 'numerical', 'integerOnly'=>true),
			array('LastName, FirstName, MiddleInitial, DateOfBirth, LastFreeAcess', 'length', 'max'=>45),
			array('OnLease', 'length', 'max'=>1),
			array('LastName, FirstName, MiddleInitial, DateOfBirth','required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, idTenant, LastName, FirstName, MiddleInitial, DateOfBirth, OnLease, LastFreeAcess', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idTenant0' => array(self::BELONGS_TO, 'Tenant', 'idTenant'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idTenant' => 'Id Tenant',
			'LastName' => 'Last Name',
			'FirstName' => 'First Name',
			'MiddleInitial' => 'Middle Initial',
			'DateOfBirth' => 'Date Of Birth',
			'OnLease' => 'On Lease',
			'LastFreeAcess' => 'Last Free Acess',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idTenant',$this->idTenant);
		$criteria->compare('LastName',$this->LastName,true);
		$criteria->compare('FirstName',$this->FirstName,true);
		$criteria->compare('t.MiddleInitial',$this->MiddleInitial,true);
		$criteria->compare('t.DateOfBirth',$this->DateOfBirth,true);
		$criteria->compare('OnLease',$this->OnLease,true);
		$criteria->compare('LastFreeAcess',$this->LastFreeAcess,true);
		$criteria->compare('Name', $this->Name, true);
		$criteria->with=array('idTenant0');
		

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}